﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Windows.Input;
using Microsoft.Practices.Composite.Presentation.Commands;

namespace Elentok.Common.Wpf.ViewModels
{
  /// <summary>
  /// Defines the view model for the recent files menu
  /// </summary>
  public interface IRecentFilesViewModel : IViewModel
  {
    /// <summary>
    /// Gets the recent files
    /// </summary>
    ReadOnlyObservableCollection<string> Files { get; }

    /// <summary>
    /// Gets the open that should be executed when a recent file menu item is clicked
    /// </summary>
    ICommand OpenFileCommand { get; }
  }

  /// <summary>
  /// The default implementation of the <see cref="IRecentFilesViewModel"/> interface.
  /// </summary>
  public class RecentFilesViewModel : ViewModelBase, IRecentFilesViewModel
  {
    private IRecentFilesService recentFilesManager;

    /// <summary>
    /// Initializes a new instance of the <see cref="RecentFilesViewModel"/> class
    /// </summary>
    /// <param name="recentFilesManager"></param>
    public RecentFilesViewModel(IRecentFilesService recentFilesManager)
    {
      this.recentFilesManager = recentFilesManager;
      this.OpenFileCommand = new DelegateCommand<string>(ExecuteOpenFileCommand);
    }

    private void ExecuteOpenFileCommand(string filename)
    {
      this.recentFilesManager.OpenFile(filename);
    }

    /// <summary>
    /// Gets the recent files
    /// </summary>
    public ReadOnlyObservableCollection<string> Files
    {
      get { return this.recentFilesManager.Files; }
    }

    /// <summary>
    /// Gets the open that should be executed when a recent file menu item is clicked
    /// </summary>
    public ICommand OpenFileCommand { get; private set; }
  }
}
